#include "CImg.h"
#include "Functions.h"

using namespace std;
using namespace cimg_library;

int main()
{
	CImg<double> marM(WIDTH, HEIGHT, 1, 3), marN(WIDTH, HEIGHT, 1, 3);


	for(int h = 0 ; h < HEIGHT; h ++)
		for(int w = 0 ; w < WIDTH; w ++)
		{
			double sinThetaI = -1.0f + (w * 2.0f) / WIDTH;
			double sinThetaO = -1.0f + (h * 2.0f) / HEIGHT;
			double thetaI = asin(sinThetaI) * 180 / PI;
			double thetaO = asin(sinThetaO) * 180 / PI;
			double thetaH = (thetaI + thetaO) / 2;

			for(int c = 0 ; c < 3; c++)
			{
				marM(w, h, 0, c) = 1.0 / (sqrt(2 * PI) * abs(b[c])) * exp(-(thetaH - a[c])*(thetaH - a[c])/2/ (b[c] * b[c]));
			}
		}
			
			
	marM.normalize(0, 255);		
	marM.save("MarM.bmp");

	for(int h = 0 ; h < HEIGHT; ++ h)
		for(int w = 0 ; w < WIDTH; ++ w)
		{
			double cosPhi = -1.0 + ( w * 2.0) / WIDTH;
			double cosThD = -1.0 + ( h * 2.0) / HEIGHT;
			double phi = acos(cosPhi);
			double thD = acos(cosThD);

			for(int c = 0; c < 3; c++)
			{
				marN(w, h, 0, c) = NP(c, phi, thD);
			}

		}

	marN.normalize(0, 255);		
	marN.save("MarN.bmp");

	CImgList<double> MarMN(marM, marN, false);
	MarMN.display();

	return 0;
}